<?php

namespace Modules\SmallApi\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\SmallApi\Service\CouponService;

class CouponController extends BaseController
{	

	/**
	 *	我的优惠券
	 *	hinq 2019 09 02
	 *	应用场景【个人中心 优惠券】
	 **/
	public function get_my_coupons( Request $request ){
		$arr_search = (array) $request->all();
		$arr_list = CouponService::get_all( (array) $arr_search );
        return response_json( $arr_list );
	}
	
	
	/**
	 *	获取优惠券详情数据
	 *	hinq 2019 09 10
	 *
	 **/
	public function get_coupon_detail( Request $request ){
		$nId = $request->get('id',0);
		$arr_list = CouponService::get_one( (int) $nId );
        return response_json( $arr_list );
	}


	/**
	 *	使用优惠券
	 *	hinq 2019 09 02
	 *	应用场景【个人中心 扫描二维码使用优惠券】
	 **/
	public function use_coupon( Request $request ){


		
		$arr_search = (array) $request->all();
		$arr_list = CouponService::edit_one( (array) $arr_search );
        return response_json( $arr_list );
	}


	//测试接口   可删除
	public function get_my_coupon_to_goods( Request $request ){

		$arr_search = (array) $request->all();
		$arr_list = CouponService::get_my_coupon_to_goods( (array) $arr_search );
        return response_json( $arr_list );

	}





	/**
	 *	手动给用户发放优惠券
	 *	hinq 2019 09 24
	 *
	 **/
	public function create_coupon_to_user(Request $request){
		$arrInput = $request->all();
		$arr_list = CouponService::create_coupon_to_user( (array) $arrInput );
		return response_json( $arr_list );
	}



	/**
	 *	会员升级发放会员等级礼包
	 *	hinq 2019 09 26
	 *
	 **/
	public function send_upgrade_material_benefits( Request $request ){
		$nId = (int) $request->get('user_id');
		$arr_list = CouponService::send_upgrade_material_benefits( (int) $nId );
 		return response_json( $arr_list );
	}








//====================== 定时任务接口 ==============================================================



	/**
	 *	定时任务调用
	 *  修改已过期的并且未使用的优惠券的状态
	 *	hinq 2019 09 23
	 *
	 **/
	public function change_coupon_status(){
		shiwu_start();
		$arr_list = CouponService::change_coupon_status();
 		shiwu_end($arr_list);
 		return response_json( $arr_list );
	}


	/**
	 *	定时任务调用
	 *	给会用用户发放设定的福利礼包
	 *	hinq 2019 09 26
	 **/
	public function send_material_benefits(){
		$arr_list = CouponService::send_material_benefits();
 		return response_json( $arr_list );
	}

    /**
     *	定时任务调用
     *	定期检测活动是否到期
     *	hinq 2019 11 27
     **/
    public function send_activity_status(){
        $arr_list = CouponService::activity_auto_cancel();
        return response_json( $arr_list );
    }







}